package co.yixiang.yshop.module.order.controller.admin.storeaftersales;

import co.yixiang.yshop.framework.common.pojo.CommonResult;
import co.yixiang.yshop.framework.common.pojo.PageResult;
import co.yixiang.yshop.module.order.controller.admin.storeaftersales.vo.StoreAfterSalesPageReqVO;
import co.yixiang.yshop.module.order.controller.admin.storeaftersales.vo.StoreAfterSalesRespVO;
import co.yixiang.yshop.module.order.controller.admin.storeaftersales.vo.StoreAfterSalesUpdateReqVO;
import co.yixiang.yshop.module.order.convert.storeaftersales.StoreAfterSalesConvert;
import co.yixiang.yshop.module.order.dal.dataobject.storeaftersales.StoreAfterSalesDO;
import co.yixiang.yshop.module.order.service.storeaftersales.StoreAfterSalesService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static co.yixiang.yshop.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 售后记录")
@RestController
@RequestMapping("/order/store-after-sales")
@Validated
public class StoreAfterSalesController {

    @Resource
    private StoreAfterSalesService storeAfterSalesService;


    @PutMapping("/update")
    @Operation(summary = "更新售后记录")
    @PreAuthorize("@ss.hasPermission('order:store-after-sales:update')")
    public CommonResult<Boolean> updateStoreAfterSales(@Valid @RequestBody StoreAfterSalesUpdateReqVO updateReqVO) throws Exception {
        storeAfterSalesService.updateStoreAfterSales(updateReqVO);
        return success(true);
    }


//    @GetMapping("/pay")
//    @Operation(summary = "立即退款")
//    @Parameter(name = "id", description = "编号", required = true)
//    @PreAuthorize("@ss.hasPermission('order:store-after-sales:delete')")
//    public CommonResult<Boolean> deleteStoreAfterSales(@RequestParam("id") Long id) throws Exception {
//        storeAfterSalesService.payStoreAfterSales(id);
//        return success(true);
//    }

    @GetMapping("/get")
    @Operation(summary = "获得售后记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('order:store-after-sales:query')")
    public CommonResult<StoreAfterSalesRespVO> getStoreAfterSales(@RequestParam("id") Long id) {
        StoreAfterSalesDO storeAfterSales = storeAfterSalesService.getStoreAfterSales(id);
        return success(StoreAfterSalesConvert.INSTANCE.convert(storeAfterSales));
    }


    @GetMapping("/page")
    @Operation(summary = "获得售后记录分页")
    @PreAuthorize("@ss.hasPermission('order:store-after-sales:query')")
    public CommonResult<PageResult<StoreAfterSalesRespVO>> getStoreAfterSalesPage(@Valid StoreAfterSalesPageReqVO pageVO) {
        return success(storeAfterSalesService.getStoreAfterSalesPage(pageVO));
    }


}
